Deklaration eines Interfaces mit Methoden-Prototypen
Syntax |
---|
|
Bedeutung |
---|
Deklaration eines →Interfaces (ein Feature der →objektorientierte Programmierung) , wobei In der Objektorientierten Programmierung trennen Sie mit Hilfe eines Interfaces die Interface-Spezifikation von ihrer Implementierung als eine →Klasse. Das erlaubt unterschiedliche Implementierungen einer gemeinsamen Interface-Spezifikation. Das Schlüsselwort |
Gut zu wissen |
---|
In einem Interface dürfen Sie nur →Methoden-Prototypen deklarieren. Siehe folgender Abschnitt "Deklaration eines Methoden-Prototyp". Ein Interface kann als Typ für eine Variable verwendet werden (siehe "Deklaration von Variablen, die auf einem Interface basieren"). Zusätzlich kann ein Funktionsbaustein oder eine →Klasse die Interfaces implementieren (siehe "Deklaration eines Funktionsbausteins in ST"). Ein Interface verhält sich wie ein →Funktionsbaustein. |
Deklaration eines Methoden-Prototyp
Ein Methoden-Prototyp ist eine eingeschränkte Deklaration einer →Methode (mit dem impliziten Modifizier PUBLIC
) zur Verwendung bei einem Interface.
Übersicht zur Syntax |
---|
|
Im Unterschied zur Methode (siehe "Deklaration einer Methode" für Details) darf ein Methoden-Prototyp nur diese Elemente enthalten:
-
der Name des Methoden-Prototypes
-
optional: der Datentyp des Methoden-Prototypes (für einen Ergebniswert)
-
optional: die Deklaration von →Eingangsvariablen, →Ausgangsvariablen und →Ein-/Ausgangsvariablen
Alle anderen Variablen (z.B. →temporäre Variablen) dürfen nicht in einem Methoden-Prototyp deklariert werden.
Beachten Sie, dass Sie bei einem Methoden-Prototyp keine Schlüsselwörter (z.B. Modifizierer) und auch keinen Body (also Code zum Ausführen) definieren, wie dies bei einer Methode möglich ist.
Beispiel 1: Interface mit 2 Methoden-Prototypen |
---|
|
Beispiel 2: Wie Beispiel 1 mit abgeleiteten Interfaces |
---|
|
Beispiel 3 |
---|
|
Weitere Beispiele für Interfaces finden Sie unter "Beispiele für Verwendung von Interfaces und Variablen basierend auf diesen Interfaces (inkl. Zuweisungen)".